package com.duobao.view;
import java.awt.*;

import javax.swing.*;

import com.duobao.game.DuobaoSwingLaunch;
import com.duobao.server.*;
import com.duobao.uitl.*;

import java.awt.event.*;
import java.util.Vector;
public class Xinxi extends JPanel implements MouseListener{
    DuobaoSwingLaunch game;
    Map heroMap;
    Vector vector;//用于分页
    int newPage;//当前页数
    JLabel jlb_nextPage;//下一页
    JLabel jlb_previousPage;//上一页
    JLabel fanhui;//返回
    JLabel fanhuiyouxi;//返回游戏

    JLabel cundang;
    JLabel shezhi;
    JLabel chenghu;
    JLabel suishu;
    JLabel chushou;
    JLabel zhuangtai;
    JLabel daiyou;
    JLabel zhuangbei[];
    JLabel jineng;
    JLabel wugong[];

    public Xinxi(DuobaoSwingLaunch game, int page)
    {
        vector=new Vector();
        this.newPage=page;
        this.game=game;
        this.heroMap=Maps.getMap(this.game.hero.getLocation());
        GridLayout gl=new GridLayout(16,1,1,1);
        this.setLayout(gl);

        setCundang_Shezhi();
        setChenghu();
        setSuishu();
        setChushou();
        setZhuangtai();
        setZhuangbei();
        setJineng();
        setWugong();
        setFanhui();
        setFanhuiyouxi();
        setadd();
    }

    public void setCundang_Shezhi() {
        cundang=new JLabel();
        cundang.addMouseListener(this);
        cundang.setFont(myFont.f2);
        cundang.setForeground(Color.BLUE);
        cundang.setText("<html><u>"+"存档"+"</u>"+"&nbsp&nbsp"+"</html>");

        shezhi=new JLabel();
        shezhi.addMouseListener(this);
        shezhi.setFont(myFont.f2);
        shezhi.setForeground(Color.BLUE);
        shezhi.setText("<html><u>"+"设置"+"</u></html>");


        JPanel jp3=new JPanel();
        jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp3.add(cundang);
        jp3.add(shezhi);
        this.vector.add(jp3);
    }


    public void setChenghu() {
        chenghu=new JLabel("【"+this.game.getHero().getChengWei()+"】"+this.game.getHero().getJiaoC()+this.game.getHero().getName());
        chenghu.addMouseListener(this);
        chenghu.setFont(myFont.f2);
        JPanel jp3=new JPanel();
        jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp3.add(chenghu);
        this.vector.add(jp3);
    }

    public void setSuishu() {
        suishu=new JLabel("今年"+this.game.getHero().getAgeDa()+"岁。");
        suishu.addMouseListener(this);
        suishu.setFont(myFont.f2);
        JPanel jp3=new JPanel();
        jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp3.add(suishu);
        this.vector.add(jp3);
    }

    public void setChushou() {
        chushou=new JLabel("武功看起来好像"+this.game.getHero().getWGMS()+",出手似乎"+this.game.getHero().getCSMS()+"。");
        chushou.addMouseListener(this);
        chushou.setFont(myFont.f2);
        JPanel jp3=new JPanel();
        jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp3.add(chushou);
        this.vector.add(jp3);
    }

    public void setZhuangtai() {
        zhuangtai=new JLabel("你看起来"+this.game.getHero().getQxue()+"。");
        zhuangtai.addMouseListener(this);
        zhuangtai.setFont(myFont.f2);
        JPanel jp3=new JPanel();
        jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp3.add(zhuangtai);
        this.vector.add(jp3);
    }

    public void setZhuangbei() {


        int a = this.game.getHero().getEquip().size();
        if(a!=0)
        {
            daiyou=new JLabel("你身上带有：");
            daiyou.addMouseListener(this);
            daiyou.setFont(myFont.f2);
            JPanel jp3=new JPanel();
            jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
            jp3.add(daiyou);
            this.vector.add(jp3);

        }
        zhuangbei = new JLabel[a];
        for(int i=0;i<a;i++)
        {
            Equip e = this.game.hero.getEquip().get(i);
            zhuangbei[i] = new JLabel("□"+e.getName());
            zhuangbei[i].addMouseListener(this);
            zhuangbei[i].setFont(myFont.f2);
            JPanel jp3=new JPanel();
            jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
            jp3.add(zhuangbei[i]);
            this.vector.add(jp3);
        }
    }

    public void setJineng() {

        jineng=new JLabel("技能有效等级：");
        jineng.addMouseListener(this);
        jineng.setFont(myFont.f2);
        JPanel jp3=new JPanel();
        jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp3.add(jineng);
        this.vector.add(jp3);
    }

    public void setWugong() {
        int b = this.game.hero.getWGs().size();
        int c = this.game.hero.getJBWGS();
        wugong = new JLabel[c];
        for(int i=0;i<b;i++)
        {
            WuGong e = this.game.hero.getWGs().get(i);
            if(e.getCategory()==2)
            {
                if(e.getPZWg()==null)
                {
                    wugong[i] = new JLabel(""+e.getName()+":"+this.game.hero.getZH()[e.getCategory2()-1]);
                }else
                {
                    wugong[i] = new JLabel(""+e.getName()+"("+e.getPZWg().getName()+"):"+this.game.hero.getZH()[e.getCategory2()-1]);
                }
                wugong[i].addMouseListener(this);
                wugong[i].setFont(myFont.f2);
                JPanel jp3=new JPanel();
                jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
                jp3.add(wugong[i]);
                this.vector.add(jp3);
            }
        }
    }

    public void setFanhui() {
        fanhui=new JLabel();
        fanhui.addMouseListener(this);
        fanhui.setFont(myFont.f2);
        fanhui.setForeground(Color.BLUE);
        fanhui.setText("<html><u>"+"返回"+"</u></html>");
        JPanel jp3=new JPanel();
        jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp3.add(fanhui);
        this.vector.add(jp3);
    }

    public void setFanhuiyouxi() {
        fanhuiyouxi=new JLabel();
        fanhuiyouxi.addMouseListener(this);
        fanhuiyouxi.setFont(myFont.f2);
        fanhuiyouxi.setForeground(Color.BLUE);
        fanhuiyouxi.setText("<html><u>"+"返回游戏"+"</u></html>");
        JPanel jp4=new JPanel();
        jp4.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp4.add(fanhuiyouxi);
        this.vector.add(jp4);
    }
    private void setadd()//加载JLabel
    {
        JPanel jPanel=new JPanel();
        jPanel.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        if(this.vector.size()<=this.newPage*15)
        {

            if(this.newPage!=1)
            {
                jlb_previousPage=new JLabel();
                jlb_previousPage.addMouseListener(this);
                jlb_previousPage.setFont(myFont.f2);
                jlb_previousPage.setForeground(Color.BLUE);
                jlb_previousPage.setText("<html><u>"+"上一页"+"</u></html>");
                jPanel.add(jlb_previousPage);
                this.vector.add(this.vector.size()-2,jPanel);
            }

            for(int i=((this.newPage-1)*15);i<this.vector.size();i++)
            {
                this.add((Component) this.vector.get(i));
            }
        }else
        {
            for(int i=((this.newPage-1)*15);i<(this.newPage)*15;i++)
            {
                this.add((Component) this.vector.get(i));
            }

            if(this.newPage!=1)
            {
                jlb_previousPage=new JLabel();
                jlb_previousPage.addMouseListener(this);
                jlb_previousPage.setFont(myFont.f2);
                jlb_previousPage.setForeground(Color.BLUE);
                jlb_previousPage.setText("<html><u>"+"上一页"+"</u></html>");
                jPanel.add(jlb_previousPage);
            }
            jlb_nextPage=new JLabel();
            jlb_nextPage.addMouseListener(this);
            jlb_nextPage.setFont(myFont.f2);
            jlb_nextPage.setForeground(Color.BLUE);
            jlb_nextPage.setText("<html><u>"+"下一页"+"</u></html>");
            jPanel.add(jlb_nextPage);
            this.add(jPanel);
        }
    }
    private boolean iFText(JLabel jl)
    {
        boolean f=true;
        if(jl==cundang || jl==shezhi || jl==jlb_nextPage || jl==jlb_previousPage || jl==fanhui || jl== fanhuiyouxi)
        {
            f=false;
        }
        return f;
    }
    public void mouseClicked(MouseEvent e) {
        // TODO Auto-generated method stub
        if(e.getSource()==jlb_nextPage)
        {
            this.game.setPanel(new Xinxi(this.game,(this.newPage+1)));
        }else if(e.getSource()==jlb_previousPage)
        {
            this.game.setPanel(new Xinxi(this.game,(this.newPage-1)));
        }else if(e.getSource()==fanhuiyouxi)
        {
            this.game.setPanel(new MainPanel(this.game,1));
        }else if(e.getSource()==fanhui)
        {
            this.game.setPanel(new ZhuangTaiPanel(this.game,null,1));
        }
    }

    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub
        if(iFText((JLabel)e.getSource()))
        {
            ((JLabel)e.getSource()).setCursor(new Cursor(Cursor.TEXT_CURSOR));
        }
    }

    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    public void mousePressed(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub

    }

}
